public class ShellSort {
    /**
     *
     * @param array
     */
    public static void sort(int[] array){

        int length = array.length;
        for(int gap=length/2;gap>0;gap=gap/2){
            for(int i=0;i<gap;i++){
                for(int j=i+gap;j<length;j=j+gap){{
                    if(array[j]<array[j-gap]){
                        int temp =array[j];
                        int k = j-gap;
                        while(k>=0 && array[k]>temp){
                            array[k+gap]=array[k];
                            k-=gap;
                        }
                        array[k+gap]=temp;
                    }
                }}
            }
        }

        }

        public static void main(String[] args) {
            int[] array={3,6,9,5,2,1,8,7,4,0};
            sort(array);
            for(int i =0;i<array.length;i++){
                System.out.println(array[i]);
            }
        }
    }
    
